﻿<div class="page-heading">
		<h1>Thêm tin tức mới</h1>
</div>
<div class="page-content">
    <div class="msg-box hidden" id="msg-newsadd">
        <span class="msg">Thêm tin tức mới thành công.</span>
    </div>
    <div class="error-box hidden" id="err-newsadd">
        
    </div>
    <form id="form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="submit" value="true" />
        
        <div class="admin-row">
            <div class="left"><label>Danh mục tin tức</label></div>
            <div class="right">
                <select id="cat_select" name="CatId">
                    <option value="0">-- Chọn danh mục tin --</option>
                    <fly:list data="view">
                        <optgroup label="{view.name}" id="opt_{view.id}"></optgroup>
                    </fly:list>
                </select>
            </div>
        </div>
        <div class="admin-row">
            <div class="left"><label>Tiêu đề</label></div>
            <div class="right"><input class="input" name="Name" type="text" value="{name}"/></div>
        </div>
        <div class="admin-row">
            <div class="left"><label>Hình ảnh</label></div>
            <div class="right">
                <input class="input" name="Image" type="file" />
            </div>
        </div>
        <div class="admin-row">
            <div class="left"><label>Giới thiệu</label></div>
            <div class="right"><textarea name="Description">{Desc}</textarea></div>
        </div>
        <div class="admin-row">
            <div class="left"><label>Chi tiết</label></div>
            <div class="right"><textarea name="Detail" id="news_detail">{Detail}</textarea></div>
        </div>
        
        <div class="admin-row">
            <div class="left">&nbsp;</div>
            <div class="right">
                <input class="button" type="submit" value="Lưu lại" />
                <a class="button" onclick="location='{BaseUrl}/admin/newslist'" >Hủy bỏ</a>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $('#news_detail').cleditor({ width: "100%", height: "500px" });
    {subcat_script}
    var sublist = jQuery.parseJSON(subcats);
    if (sublist != null) {

        $.each(sublist, function (i, subcat) {
            $('#opt_' + subcat.ParentId).append('<option value="'+subcat.Id+'">'+subcat.Name+'</option>');
        });
    }
    {tag_script}
    var taglist = jQuery.parseJSON(tags); //{Id:1;TagValue:heoheo}
    for (var i in taglist) {
        taglist[i].value = taglist[i].TagValue;
        taglist[i].label = taglist[i].TagValue;
    }
    if (taglist != null) {
        $('#TagInput').autocomplete({
            source: taglist,
            select: function (e, ui) {
                $('#tagbox').append('<span id="tagitem_' + ui.item.id + '" tagId=' + ui.item.id + '>' + ui.item.value + '<a class="remove_tag" onclick="removeTag(' + ui.item.id + ')">X</a></span>');
            }
        });
    }
    $('#form').submit(function () {
        var str = "";
        $('#tagbox').find('span').each(function () {
            str += $(this).attr('tagId') + ",";
        });
        str = str.substring(0, str.lastIndexOf(","));
        $('#tagsFormData').val(str);
        return true;
    });
    function removeTag(tagId) {
        $('#tagitem_' + tagId).remove();
    }
</script>


